﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SilverlightRest
{
    //public class CompressedContent : HttpContent
    //{
    //    private readonly HttpContent originalContent;
    //    private readonly string encodingType;


    //    public CompressedContent(HttpContent content, string encodingType)
    //    {
    //        if (content == null)
    //        {
    //            throw new ArgumentNullException("content");
    //        }


    //        if (encodingType == null)
    //        {
    //            throw new ArgumentNullException("encodingType");
    //        }


    //        originalContent = content;
    //        this.encodingType = encodingType.ToLowerInvariant();


    //        if (this.encodingType != "gzip" && this.encodingType != "deflate")
    //        {
    //            throw new InvalidOperationException(string.Format("Encoding '{0}' is not supported. Only supports gzip or deflate encoding.", this.encodingType));
    //        }


    //        foreach (KeyValuePair<string, IEnumerable<string>> header in originalContent.Headers)
    //        {
    //            Headers.TryAddWithoutValidation(header.Key, header.Value);
    //        }


    //        Headers.ContentEncoding.Add(encodingType);
    //    }


    //    protected override bool TryComputeLength(out long length)
    //    {
    //        length = -1;


    //        return false;
    //    }


    //    protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)
    //    {
    //        Stream compressedStream = null;


    //        if (encodingType == "gzip")
    //        {
    //            //compressedStream = new GZipStream(stream, CompressionMode.Compress, leaveOpen: true);
    //            compressedStream = new ZlibStream(stream, CompressionMode.Compress, leaveOpen: true);
    //        }
    //        else if (encodingType == "deflate")
    //        {
    //            compressedStream = new DeflateStream(stream, CompressionMode.Compress, leaveOpen: true);
    //        }


    //        return originalContent.CopyToAsync(compressedStream).ContinueWith(tsk =>
    //        {
    //            if (compressedStream != null)
    //            {
    //                compressedStream.Dispose();
    //            }
    //        });
    //    }
    //}

}
